package RC4;

public class RC4Test {

    private static final RC4TestData[] testData = new RC4TestData[]{
            new RC4TestData("6e6f742d736f2d72616e646f6d2d6b6579",
                    "476f6f6420796f752061726520636f7272656374",
                    "2d7fee79ffc080b096f7ef99e8ee659c328e065f"),
            new RC4TestData("3475bd76fa040b73f521ffcd9de93f24",
                    "1b5e8b0f1bc78d238064826704830cdb",
                    "227ffc688734f86fa15615750080c586"),
            new RC4TestData("2b24424b9fed596659842a4d0b007c61",
                    "41b267bc5905f0a3cd691b3ddaee149d",
                    "f508c68cf099856bde9a88cb1d3c589b"),
            new RC4TestData("0f1571c947d9e8590cb7add6af7f6798",
                    "0123456789abcdeffedcba9876543210",
                    "4dd28d94f5d0bfa9777e82ba06a5bef9"),
            new RC4TestData("1234567890123456789012345678901234567890abcd",
                    "123456789012345678901234567890ab",
                    "d94736a36713a7652185d8a15241ed23")
    };

    private static class RC4TestData {
        private final String key;
        private final String plaintext;
        private final String ciphertext;


        public RC4TestData(String key, String plaintext, String ciphertext) {
            this.key = key;
            this.plaintext = plaintext;
            this.ciphertext = ciphertext;
        }

        public String getKey() {
            return key;
        }

        public String getPlaintext() {
            return plaintext;
        }

        public String getCiphertext() {
            return ciphertext;
        }
    }

    private static void primaryTest() {

        RC4 rc4 = new RC4();

        boolean flag = true;

        for (RC4TestData data : testData) {
            String encryptData = rc4.encrypt(data.getPlaintext(), data.getKey());
            if (!encryptData.equals(data.getCiphertext())) {
                flag = false;
            }
            String decryptData = rc4.decrypt(encryptData, data.getKey());
            if (!decryptData.equals(data.getPlaintext())) {
                flag = false;
            }
        }

        if (flag) {
            System.out.println("RC4Test.primaryTest：测试通过");
        } else {
            System.out.println("RC4Test.primaryTest：测试不通过");
        }

    }

    public static void main(String[] args) {
        primaryTest();
    }

}
